package com.sendables;

import java.awt.Color;
import java.awt.Graphics;

import com.exception.IllegalPackageException;

public abstract class Paintable extends Sendable {
	public static final int	TYPE_POSITION	= 5;
	protected int			ownerId;
	protected DoodlePoint	start;
	protected Color			c;

	protected Paintable(int ownerId, Color c, DoodlePoint start)
	{
		super();
		this.ownerId = ownerId;
		this.c = c;
		this.start = start;
	}

	protected Paintable()
	{
	}

	public String toString()
	{
		return "OwnerId: " + ownerId + " Color: " + c + " Start: " + start;
	}

	public abstract void paint(Graphics g);

	@Override
	public int getAlloc()
	{
		return start.getAlloc() + alloc(ownerId) + alloc(c.getRGB()) + BYTE_SIZE;
	}

	@Override
	public void writeByteRepresentation(byte[] b, int[] offset)
	{
		new Number(ownerId).writeByteRepresentation(b, offset);
		new Number(c.getRGB()).writeByteRepresentation(b, offset);
		start.writeByteRepresentation(b, offset);
	}

	protected void parseSuper(byte[] b, int[] offset) throws IllegalPackageException
	{
		ownerId = Number.parse(b, offset).getContent();
		c = new Color(Number.parse(b, offset).getContent());
		start = DoodlePoint.parse(b, offset);
	}

	public Integer getId()
	{
		return ownerId;
	}

}
